package ChaiPiao.util;

import org.json.JSONObject;

import java.util.Map;
import java.util.Set;

public class MapUtil {

    /*
    set all the same value
     */
    public static <KEY, VALUE> void setValue(Map<KEY, VALUE> map, VALUE value) {
        Set<KEY> keySet = map.keySet();
        for (KEY key : keySet) {
            map.put(key, value);
        }
    }

    /*
   set all the same value if key contains containsString
    */
    public static <VALUE> void setValue(Map<String, VALUE> map, String containsString, VALUE value) {
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            if (key.contains(containsString))
                map.put(key, value);
        }
    }

    public static <KEY, VALUE> JSONObject toJson(Map<KEY, VALUE> map) {
        if (map == null)
            return null;
        JSONObject jsonObject = new JSONObject();
        Set<KEY> keySet = map.keySet();
        for (KEY key : keySet) {
            jsonObject.put(key.toString(), map.get(key).toString());
        }
        return jsonObject;
    }

    public static void main(String[] args) {
        System.out.println("".contains(""));
    }
}
